# Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 Cygnus Support
#
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
# license, or royalty fee is required for any of the authorized uses.
# Modifications to this software may be copyrighted by their authors
# and need not follow the licensing terms described here, provided that
# the new terms are clearly indicated on the first page of each file where
# they apply.

DESTDIR =
VPATH = @srcdir@
srcdir = @srcdir@
objdir = .
srcroot = $(srcdir)/../..
objroot = $(objdir)/../..

prefix = @prefix@
exec_prefix = @exec_prefix@

host_alias = @host_alias@
target_alias = @target_alias@
program_transform_name = @program_transform_name@

bindir = @bindir@
libdir = @libdir@
tooldir = $(exec_prefix)/$(target_alias)

# Multilib support variables.
# TOP is used instead of MULTI{BUILD,SRC}TOP.
MULTIDIRS =
MULTISUBDIR =
MULTIDO = true
MULTICLEAN = true

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

SHELL =	/bin/sh

CC = @CC@

#AS = @AS@
AS = `if [ -f ${objroot}/../gas/as.new ] ; \
	then echo ${objroot}/../gas/as.new ; \
	else echo as ; fi`

AR = @AR@

#LD = @LD@
LD = `if [ -f ${objroot}/../ld/ld.new ] ; \
	then echo ${objroot}/../ld/ld.new ; \
	else echo ld ; fi`

RANLIB = @RANLIB@

OBJDUMP = `if [ -f ${objroot}/../binutils/objdump ] ; \
	then echo ${objroot}/../binutils/objdump ; \
	else t='$(program_transform_name)'; echo objdump | sed -e $$t ; fi`
OBJCOPY = `if [ -f ${objroot}/../binutils/objcopy ] ; \
	then echo ${objroot}/../binutils/objcopy ; \
	else t='$(program_transform_name)'; echo objcopy | sed -e $$t ; fi`

CRT0 = @MIPS_CRT0@
PCRT0 = pcrt0.o
GENOBJS = syscalls.o fstat.o getpid.o isatty.o kill.o \
	lseek.o print.o putnum.o stat.o unlink.o __exit.o link.o \
	get_ram_range.o
GENOBJS2 = open.o close.o read.o write.o
IDTOBJS = idtmon.o @MIPS_PART_SPECIFIC_OBJ@ ${GENOBJS}
PMONOBJS = pmon.o @MIPS_PART_SPECIFIC_OBJ@ ${GENOBJS}
LSIOBJS = lsipmon.o @MIPS_PART_SPECIFIC_OBJ@ ${GENOBJS}
DVEOBJS = dvemon.o @MIPS_PART_SPECIFIC_OBJ@ ${GENOBJS} ${GENOBJS2}
JMR3904OBJS = jmr3904-io.o @MIPS_PART_SPECIFIC_OBJ@ ${GENOBJS} ${GENOBJS2}
CFEOBJS = cfe.o cfe_api.o cfe_mem.o @MIPS_PART_SPECIFIC_OBJ@ ${GENOBJS} ${GENOBJS2}
CYGMONOBJS = open.o close.o cygmon.o @MIPS_PART_SPECIFIC_OBJ@ ${GENOBJS}


ISROBJS = mips_excpt_isr_fallback.o
ISROBJS += mips_excpt_isr_000.o mips_excpt_isr_001.o mips_excpt_isr_002.o
ISROBJS += mips_excpt_isr_003.o mips_excpt_isr_004.o mips_excpt_isr_005.o
ISROBJS += mips_excpt_isr_006.o mips_excpt_isr_007.o mips_excpt_isr_008.o
ISROBJS += mips_excpt_isr_009.o mips_excpt_isr_010.o mips_excpt_isr_011.o
ISROBJS += mips_excpt_isr_012.o mips_excpt_isr_013.o mips_excpt_isr_014.o
ISROBJS += mips_excpt_isr_015.o mips_excpt_isr_016.o mips_excpt_isr_017.o
ISROBJS += mips_excpt_isr_018.o mips_excpt_isr_019.o mips_excpt_isr_020.o
ISROBJS += mips_excpt_isr_021.o mips_excpt_isr_022.o mips_excpt_isr_023.o
ISROBJS += mips_excpt_isr_024.o mips_excpt_isr_025.o mips_excpt_isr_026.o
ISROBJS += mips_excpt_isr_027.o mips_excpt_isr_028.o mips_excpt_isr_029.o
ISROBJS += mips_excpt_isr_030.o mips_excpt_isr_031.o mips_excpt_isr_032.o
ISROBJS += mips_excpt_isr_033.o mips_excpt_isr_034.o mips_excpt_isr_035.o
ISROBJS += mips_excpt_isr_036.o mips_excpt_isr_037.o mips_excpt_isr_038.o
ISROBJS += mips_excpt_isr_039.o mips_excpt_isr_040.o mips_excpt_isr_041.o
ISROBJS += mips_excpt_isr_042.o mips_excpt_isr_043.o mips_excpt_isr_044.o
ISROBJS += mips_excpt_isr_045.o mips_excpt_isr_046.o mips_excpt_isr_047.o
ISROBJS += mips_excpt_isr_048.o mips_excpt_isr_049.o mips_excpt_isr_050.o
ISROBJS += mips_excpt_isr_051.o mips_excpt_isr_052.o mips_excpt_isr_053.o
ISROBJS += mips_excpt_isr_054.o mips_excpt_isr_055.o mips_excpt_isr_056.o
ISROBJS += mips_excpt_isr_057.o mips_excpt_isr_058.o mips_excpt_isr_059.o
ISROBJS += mips_excpt_isr_060.o mips_excpt_isr_061.o mips_excpt_isr_062.o
ISROBJS += mips_excpt_isr_063.o mips_excpt_isr_064.o mips_excpt_isr_065.o
ISROBJS += mips_excpt_isr_066.o mips_excpt_isr_067.o mips_excpt_isr_068.o
ISROBJS += mips_excpt_isr_069.o mips_excpt_isr_070.o mips_excpt_isr_071.o
ISROBJS += mips_excpt_isr_072.o mips_excpt_isr_073.o mips_excpt_isr_074.o
ISROBJS += mips_excpt_isr_075.o mips_excpt_isr_076.o mips_excpt_isr_077.o
ISROBJS += mips_excpt_isr_078.o mips_excpt_isr_079.o mips_excpt_isr_080.o
ISROBJS += mips_excpt_isr_081.o mips_excpt_isr_082.o mips_excpt_isr_083.o
ISROBJS += mips_excpt_isr_084.o mips_excpt_isr_085.o mips_excpt_isr_086.o
ISROBJS += mips_excpt_isr_087.o mips_excpt_isr_088.o mips_excpt_isr_089.o
ISROBJS += mips_excpt_isr_090.o mips_excpt_isr_091.o mips_excpt_isr_092.o
ISROBJS += mips_excpt_isr_093.o mips_excpt_isr_094.o mips_excpt_isr_095.o
ISROBJS += mips_excpt_isr_096.o mips_excpt_isr_097.o mips_excpt_isr_098.o
ISROBJS += mips_excpt_isr_099.o mips_excpt_isr_100.o mips_excpt_isr_101.o
ISROBJS += mips_excpt_isr_102.o mips_excpt_isr_103.o mips_excpt_isr_104.o
ISROBJS += mips_excpt_isr_105.o mips_excpt_isr_106.o mips_excpt_isr_107.o
ISROBJS += mips_excpt_isr_108.o mips_excpt_isr_109.o mips_excpt_isr_110.o
ISROBJS += mips_excpt_isr_111.o mips_excpt_isr_112.o mips_excpt_isr_113.o
ISROBJS += mips_excpt_isr_114.o mips_excpt_isr_115.o mips_excpt_isr_116.o
ISROBJS += mips_excpt_isr_117.o mips_excpt_isr_118.o mips_excpt_isr_119.o
ISROBJS += mips_excpt_isr_120.o mips_excpt_isr_121.o mips_excpt_isr_122.o
ISROBJS += mips_excpt_isr_123.o mips_excpt_isr_124.o mips_excpt_isr_125.o
ISROBJS += mips_excpt_isr_126.o mips_excpt_isr_127.o mips_excpt_isr_128.o
ISROBJS += mips_excpt_isr_129.o mips_excpt_isr_130.o mips_excpt_isr_131.o
ISROBJS += mips_excpt_isr_132.o mips_excpt_isr_133.o mips_excpt_isr_134.o
ISROBJS += mips_excpt_isr_135.o mips_excpt_isr_136.o mips_excpt_isr_137.o
ISROBJS += mips_excpt_isr_138.o mips_excpt_isr_139.o mips_excpt_isr_140.o
ISROBJS += mips_excpt_isr_141.o mips_excpt_isr_142.o mips_excpt_isr_143.o
ISROBJS += mips_excpt_isr_144.o mips_excpt_isr_145.o mips_excpt_isr_146.o
ISROBJS += mips_excpt_isr_147.o mips_excpt_isr_148.o mips_excpt_isr_149.o
ISROBJS += mips_excpt_isr_150.o mips_excpt_isr_151.o mips_excpt_isr_152.o
ISROBJS += mips_excpt_isr_153.o mips_excpt_isr_154.o mips_excpt_isr_155.o
ISROBJS += mips_excpt_isr_156.o mips_excpt_isr_157.o mips_excpt_isr_158.o
ISROBJS += mips_excpt_isr_159.o mips_excpt_isr_160.o mips_excpt_isr_161.o
ISROBJS += mips_excpt_isr_162.o mips_excpt_isr_163.o mips_excpt_isr_164.o
ISROBJS += mips_excpt_isr_165.o mips_excpt_isr_166.o mips_excpt_isr_167.o
ISROBJS += mips_excpt_isr_168.o mips_excpt_isr_169.o mips_excpt_isr_170.o
ISROBJS += mips_excpt_isr_171.o mips_excpt_isr_172.o mips_excpt_isr_173.o
ISROBJS += mips_excpt_isr_174.o mips_excpt_isr_175.o mips_excpt_isr_176.o
ISROBJS += mips_excpt_isr_177.o mips_excpt_isr_178.o mips_excpt_isr_179.o
ISROBJS += mips_excpt_isr_180.o mips_excpt_isr_181.o mips_excpt_isr_182.o
ISROBJS += mips_excpt_isr_183.o mips_excpt_isr_184.o mips_excpt_isr_185.o
ISROBJS += mips_excpt_isr_186.o mips_excpt_isr_187.o mips_excpt_isr_188.o
ISROBJS += mips_excpt_isr_189.o mips_excpt_isr_190.o mips_excpt_isr_191.o
ISROBJS += mips_excpt_isr_192.o mips_excpt_isr_193.o mips_excpt_isr_194.o
ISROBJS += mips_excpt_isr_195.o mips_excpt_isr_196.o mips_excpt_isr_197.o
ISROBJS += mips_excpt_isr_198.o mips_excpt_isr_199.o mips_excpt_isr_200.o
ISROBJS += mips_excpt_isr_201.o mips_excpt_isr_202.o mips_excpt_isr_203.o
ISROBJS += mips_excpt_isr_204.o mips_excpt_isr_205.o mips_excpt_isr_206.o
ISROBJS += mips_excpt_isr_207.o mips_excpt_isr_208.o mips_excpt_isr_209.o
ISROBJS += mips_excpt_isr_210.o mips_excpt_isr_211.o mips_excpt_isr_212.o
ISROBJS += mips_excpt_isr_213.o mips_excpt_isr_214.o mips_excpt_isr_215.o
ISROBJS += mips_excpt_isr_216.o mips_excpt_isr_217.o mips_excpt_isr_218.o
ISROBJS += mips_excpt_isr_219.o mips_excpt_isr_220.o mips_excpt_isr_221.o
ISROBJS += mips_excpt_isr_222.o mips_excpt_isr_223.o mips_excpt_isr_224.o
ISROBJS += mips_excpt_isr_225.o mips_excpt_isr_226.o mips_excpt_isr_227.o
ISROBJS += mips_excpt_isr_228.o mips_excpt_isr_229.o mips_excpt_isr_230.o
ISROBJS += mips_excpt_isr_231.o mips_excpt_isr_232.o mips_excpt_isr_233.o
ISROBJS += mips_excpt_isr_234.o mips_excpt_isr_235.o mips_excpt_isr_236.o
ISROBJS += mips_excpt_isr_237.o mips_excpt_isr_238.o mips_excpt_isr_239.o
ISROBJS += mips_excpt_isr_240.o mips_excpt_isr_241.o mips_excpt_isr_242.o
ISROBJS += mips_excpt_isr_243.o mips_excpt_isr_244.o mips_excpt_isr_245.o
ISROBJS += mips_excpt_isr_246.o mips_excpt_isr_247.o mips_excpt_isr_248.o
ISROBJS += mips_excpt_isr_249.o mips_excpt_isr_250.o mips_excpt_isr_251.o
ISROBJS += mips_excpt_isr_252.o mips_excpt_isr_253.o mips_excpt_isr_254.o
ISROBJS += mips_excpt_isr_255.o

UHIOBJS = uhi_assert.o uhi_close.o uhi_exit.o uhi_fstat.o \
  uhi_lseek.o uhi_open.o uhi_plog.o \
  uhi_pread.o uhi_pwrite.o uhi_read.o uhi_link.o uhi_stat.o \
  uhi_unlink.o uhi_write.o uhi_getargs.o uhi_exception.o \
  uhi_get_ram_range.o uhi_indirect.o uhi_break.o \
  syscalls.o getpid.o isatty.o kill.o

YAMONOBJS = yamon_read.o yamon_write.o yamon_exit.o yamon_close.o \
  yamon_fstat.o yamon_exception.o

HALOBJ = mips_clean_cache.o mips_flush_cache.o mips_l2size.o \
  mips_lock_cache.o mips_size_cache.o mips_sync_cache.o \
  mips_fp.o \
  mips_excpt_entry.o mips_excpt_handler.o mips_excpt_handler_quiet.o \
  mips_excpt_register.o mips_excpt_boot.o \
  mips_intctrl.o $(ISROBJS)

HALOBJ += mips_tlb.o

HALOBJ += mips64_tlb.o mips_xpa.o mips_msa.o

BOOTOBJ = reset.o init_cp0.o init_caches.o init_tlb.o init_l23caches.o

CM3OBJ_IMPL = mips_cm3_l2size.o init_cm3l2.o

CM3AR = libcm3.a

# Nullmon cannot support read and write, but the test cases pull them in via libs
NULLMONOBJS = nullmon.o @MIPS_PART_SPECIFIC_OBJ@ ${GENOBJS}

GCC_LDFLAGS = `if [ -d ${objroot}/../gcc ] ; \
	then echo -L${objroot}/../gcc ; fi`

SCRIPTS = @MIPS_SCRIPT_LIST@
BSP = @MIPS_BSP_LIST@

PART_SPECIFIC_DEFINES = @MIPS_PART_SPECIFIC_DEFINES@

# Host specific makefile fragment comes in here.
@host_makefile_frag@

HALCFLAGS += -g \
	    -fdebug-prefix-map=$(srcdir)=$(DESTDIR)$(exec_prefix)/share/mips \
	    -fdebug-prefix-map=$(srcdir)/include=$(DESTDIR)$(exec_prefix)/$(target_alias)/include \
	    -Wa,--debug-prefix-map=$(srcdir)=$(DESTDIR)$(exec_prefix)/share/mips \
	    -Wa,--debug-prefix-map=$(srcdir)/include=$(DESTDIR)$(exec_prefix)/$(target_alias)/include \
	    -Werror

HALCFLAGS += -I $(srcdir)/include
#
# build a test program for each target board. Just trying to get
# it to link is a good test, so we ignore all the errors for now.
#

all: ${CRT0} ${PCRT0} test.o ${BSP}

#
# here's where we build the board support packages for each target
#
mipsidt.o: $(IDTOBJS)
	${LD} -r $(IDTOBJS) -o $@

mipspmon.o: $(PMONOBJS)
	${LD} -r $(PMONOBJS) -o $@

mipslsi.o: $(PMONOBJS)
	${LD} -r $(LSIOBJS) -o $@

libidt.a: $(IDTOBJS)
	${AR} ${ARFLAGS} $@ $(IDTOBJS)
	${RANLIB} $@

libpmon.a: $(PMONOBJS)
	${AR} ${ARFLAGS} $@ $(PMONOBJS)
	${RANLIB} $@

liblsi.a: $(LSIOBJS)
	${AR} ${ARFLAGS} $@ $(LSIOBJS)
	${RANLIB} $@

libdve.a: $(DVEOBJS)
	${AR} ${ARFLAGS} $@ $(DVEOBJS)
	${RANLIB} $@

libjmr3904.a: $(JMR3904OBJS)
	${AR} ${ARFLAGS} $@ $(JMR3904OBJS)
	${RANLIB} $@

libcygmon.a: $(CYGMONOBJS)
	${AR} ${ARFLAGS} $@ $(CYGMONOBJS)
	${RANLIB} $@

libcfe.a: $(CFEOBJS)
	${AR} ${ARFLAGS} $@ $(CFEOBJS)
	${RANLIB} $@

libuhi.a: $(UHIOBJS)
	${AR} ${ARFLAGS} $@ $(UHIOBJS)
	${RANLIB} $@

libyamon.a: $(YAMONOBJS)
	${AR} ${ARFLAGS} $@ $(YAMONOBJS)
	${RANLIB} $@

libhal.a: $(HALOBJ) $(BOOTOBJ)
	${AR} ${ARFLAGS} $@ $^
	${RANLIB} $@

libcm3_impl.a: $(CM3OBJ_IMPL)
	${AR} ${ARFLAGS} $@ $^
	${RANLIB} $@

# nullmon.a , This is what you want if you want crt0 but NO mon services
# Supports GDB sim testing, board bringups, ICE operation.
libnullmon.a: $(NULLMONOBJS)
	${AR} ${ARFLAGS} $@ $(NULLMONOBJS)
	${RANLIB} $@


# compile a fully linked binary. The -Wl,-T*.ld is for the linker
# script. By using -Wl, the linker script is put on the proper place
# in the comand line for ld, and all the symbols will get fully
# resolved.

test: $(OBJS) ${BSP} pmon-test idt-test cfe-test
	@echo Done...

dtor.o:  $(srcdir)/dtor.C
	$(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) -o $@ -c $<
dtor.x: dtor.o ${CRT0} ${srcdir}/pmon.ld Makefile libpmon.a
	${CC} $(CFLAGS_FOR_TARGET) -L${srcdir} -L${objdir} \
	dtor.o -o $@ $(NEWLIB_LDFLAGS) -N -Wl,-Tpmon.ld

pmon-test.x: test.o ${CRT0} Makefile libpmon.a
	${CC} $(CFLAGS_FOR_TARGET) -L${srcdir} -L${objdir} \
	test.o -o $@ $(NEWLIB_LDFLAGS) -Wl,-Tpmon.ld
pmon-test.srec: pmon-test.x
	$(OBJCOPY) -O srec pmon-test.x $@
pmon-test.dis: pmon-test.x
	@rm -fr pmon-test.dis
	$(OBJDUMP) -d pmon-test.x > $@
pmon-test: pmon-test.srec pmon-test.dis

idt-test.x: test.o ${CRT0} Makefile libidt.a
	${CC} $(CFLAGS_FOR_TARGET) -L${srcdir} -L${objdir} \
	test.o -o $@ $(NEWLIB_LDFLAGS) -Wl,-Tidt.ld
idt-test.srec: idt-test.x
	$(OBJCOPY) -O srec idt-test.x $@
idt-test.dis: idt-test.x
	@rm -fr idt-test.dis
	$(OBJDUMP) -d idt-test.x > $@
idt-test: idt-test.srec idt-test.dis

cfe-test.x: test.o ${CRT0} Makefile libcfe.a
	${CC} $(CFLAGS_FOR_TARGET) -L${srcdir} -L${objdir} \
	test.o -o $@ $(NEWLIB_LDFLAGS) -Wl,-Tcfe.ld
cfe-test.srec: cfe-test.x
	$(OBJCOPY) -O srec cfe-test.x $@
cfe-test.dis: cfe-test.x
	@rm -fr cfe-test.dis
	$(OBJDUMP) -d cfe-test.x > $@
cfe-test: cfe-test.srec cfe-test.dis

doc:

clean mostlyclean:
	rm -f a.out core *.i *~ *.a *.o *-test *.srec *.dis *.map *.x

distclean maintainer-clean realclean: clean
	rm -f Makefile config.status a.out

.PHONY: install info install-info clean-info
install:
	mkdir -p $(DESTDIR)$(tooldir)/lib${MULTISUBDIR}
	@for file in $(CRT0) $(PCRT0) $(BSP); do \
	  $(INSTALL_DATA) $${file} $(DESTDIR)$(tooldir)/lib${MULTISUBDIR}/$${file}; \
	done
	$(INSTALL_DATA) ${srcdir}/hal/libcm3.a $(DESTDIR)$(tooldir)/lib${MULTISUBDIR}/libcm3.a
	@for script in ${SCRIPTS}; do\
	  $(INSTALL_DATA) ${srcdir}/$${script}.ld $(DESTDIR)$(tooldir)/lib${MULTISUBDIR}/$${script}.ld; \
	done
	mkdir -p $(DESTDIR)$(tooldir)/include/mips
	@for header in ${srcdir}/include/mips/*.h; do\
	  $(INSTALL_DATA) $${header} $(DESTDIR)$(tooldir)/include/mips; \
	done
	@for file in ${srcdir}/include/mips/*.S; do\
	  $(INSTALL_DATA) $${file} $(DESTDIR)$(tooldir)/include/mips; \
	done
	mkdir -p $(DESTDIR)$(exec_prefix)/share/mips/boot
	@for file in ${srcdir}/boot/*.[hS] ; do\
	  $(INSTALL_DATA) $${file} $(DESTDIR)$(exec_prefix)/share/mips/boot/; \
	done
	mkdir -p $(DESTDIR)$(exec_prefix)/share/mips/hal
	@for file in ${srcdir}/hal/*.[hSc]; do\
	  $(INSTALL_DATA) $${file} $(DESTDIR)$(exec_prefix)/share/mips/hal/; \
	done
	mkdir -p $(DESTDIR)$(exec_prefix)/share/mips/uhi
	@for file in ${srcdir}/uhi/uhi_*.[hSc] ${srcdir}/uhi/yamon_*.[hSc]; do\
	  $(INSTALL_DATA) $${file} $(DESTDIR)$(exec_prefix)/share/mips/uhi/; \
	done
	mkdir -p $(DESTDIR)$(exec_prefix)/share/mips/rules
	@$(INSTALL_DATA) ${srcdir}/rules/mipshal.mk $(DESTDIR)$(exec_prefix)/share/mips/rules/
	@$(INSTALL_PROGRAM) ${srcdir}/rules/srec2hex.pl $(DESTDIR)$(exec_prefix)/share/mips/rules/

info:
install-info:
clean-info:

test.o:	${srcdir}/test.c

# these are for the BSPs
crt0.o: ${srcdir}/hal/crt0.S
	$(CC) -c $(CFLAGS_FOR_TARGET) $(HALCFLAGS) $(CFLAGS) $(INCLUDES) $^ -o $@
pcrt0.o: ${srcdir}/hal/crt0.S
	$(CC) -c $(CFLAGS_FOR_TARGET) $(HALCFLAGS) $(CFLAGS) $(INCLUDES) -DGCRT0 $^ -o ${PCRT0}
crt0_cfe.o: ${srcdir}/crt0_cfe.S
crt0_cygmon.o: ${srcdir}/crt0_cygmon.S
idtmon.o: ${srcdir}/idtmon.S
pmon.o: ${srcdir}/pmon.S
	$(CC) -c $(CFLAGS_FOR_TARGET) $(HALCFLAGS) $(CFLAGS) $(PART_SPECIFIC_DEFINES) $^ -o $@
vr4300.o: ${srcdir}/vr4300.S
	$(CC) -c $(CFLAGS_FOR_TARGET) $(CFLAGS) $^ -o $@
vr5xxx.o: ${srcdir}/vr5xxx.S
	$(CC) -c $(CFLAGS_FOR_TARGET) $(CFLAGS) $^ -o $@
lsipmon.o: $(srcdir)/lsipmon.S $(srcdir)/pmon.S
__exit.o: ${srcdir}/hal/__exit.c
	$(CC) -c $(CFLAGS_FOR_TARGET) $(HALCFLAGS) $(INCLUDES) $(CFLAGS) $^ -o $@
jmr3904-io.o: ${srcdir}/jmr3904-io.c
	$(CC) -c $(CFLAGS_FOR_TARGET) $(CFLAGS) $^ -o $@
cfe.o: ${srcdir}/cfe.c ${srcdir}/cfe_api.h
	$(CC) -c $(CFLAGS_FOR_TARGET) $(CFLAGS) $< -o $@
cfe_api.o: ${srcdir}/cfe_api.c ${srcdir}/cfe_api.h ${srcdir}/cfe_api_int.h
	$(CC) -c $(CFLAGS_FOR_TARGET) $(CFLAGS) $< -o $@
cfe_mem.o: ${srcdir}/cfe_mem.c ${srcdir}/cfe_api.h
	$(CC) -c $(CFLAGS_FOR_TARGET) $(CFLAGS) $< -o $@

# cma101 can not be compiled mips16, if a mips16 version is needed then
# it will have to be built, then this rule can be scrapped, allowing
# the implicit rule to run.
cma101.o: ${srcdir}/cma101.c
	$(CC) -c $(CFLAGS_FOR_TARGET) -O2 $(HALCFLAGS) $(INCLUDES) $(CFLAGS) -mno-mips16 $^

# cygmon can not be compiled as mips16 since it uses the syscall instruction
cygmon.o: ${srcdir}/cygmon.c
	$(CC) -c $(CFLAGS_FOR_TARGET) -O2 $(HALCFLAGS) $(INCLUDES) $(CFLAGS) -mno-mips16 $^

syscalls.o: ${srcdir}/hal/syscalls.c
	$(CC) -c $(CFLAGS_FOR_TARGET) $(HALCFLAGS) $(INCLUDES) $(CFLAGS) $< -o $@

# target specific makefile fragment comes in here.
@target_makefile_frag@

Makefile: Makefile.in ../config.status
	cd .. && $(SHELL) config.status
